import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
var _excluded = ["type", "title", "size", "color", "className", "tipProps", "style"];
import React from 'react';
import { Tooltip } from 'antd';
import classNames from 'classnames';
import { getEnvConfig } from "../../utils/iocUtils";
import cpaasIconFont from "./iconfont.css?modules";
import { CPAAS_ORIGIN_ICON_NAME } from "./Status";
/**
 * Icons 组件 - 使用iconfont图标库
 * 图标的更新方式：
 * 1. 登录iconfont，添加图标，规范化图标的名称；
 * 2. 在图标项目中的Font Class中更新, 生成新的图标样式链接，例如：//at.alicdn.com/t/font_1089395_95h9j1chzts.css；
 * 3. 将 src/utils/icon.js 中的 aliUrl 属性替换为新的图标样式链接；
 * 4. 执行 yarn icon 命名下载图标文件
 * 5. 引入Icons组件，type属性值为除去公共后缀后的图标名称，
 * 比如，cpaas-icon-edit，cpaas-icon-是公共命名，edit是图标名称，
 * 所以，type="edit"
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {!string} [type = ''] - 图标名称，例如 cpaas-icon-edit, 取edit
 * @reactProps {?string} [size = ''] - 图标大小，默认以px为单位
 * @reactProps {?string} [color = ''] - 图标颜色，支持16进制或者rgb/rgba形式
 * @reactProps {?string} [className = ''] - class属性
 * @reactProps {?string} [title = ''] - tooltip提示文字，设置该属性将自动使用Tooltip
 * @reactProps {?object} [tipProps = {}] - Tooltip其余属性
 * @reactProps {?object} [style = {}] - style样式
 * @example
 * import Icons from 'components/Icons';
 *
 * <Icons type="edit" />
 */

var Icons = /*#__PURE__*/function (_React$Component) {
  _inherits(Icons, _React$Component);

  var _super = _createSuper(Icons);

  function Icons(props) {
    var _this;

    _classCallCheck(this, Icons);

    _this = _super.call(this, props);
    _this.state = {
      iconfontplus: {}
    };
    _this.config = getEnvConfig();
    return _this;
  }

  _createClass(Icons, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      // 加载客制化图标
      this.loadAllIconsAsync();
    }
  }, {
    key: "loadAllIconsAsync",
    value: function () {
      var _loadAllIconsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        var _this2 = this;

        var iconsPath,
            _args = arguments;
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                iconsPath = _args.length > 0 && _args[0] !== undefined ? _args[0] : 'iconfont.css';
                _context.next = 3;
                return import("@/assets/icons/".concat(iconsPath)).then(function () {
                  var m1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
                  var cssObj = m1.default || {};

                  _this2.setState({
                    iconfontplus: cssObj
                  });
                }).catch(function () {
                  _this2.setState({
                    iconfontplus: {}
                  });
                });

              case 3:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }));

      function loadAllIconsAsync() {
        return _loadAllIconsAsync.apply(this, arguments);
      }

      return loadAllIconsAsync;
    }()
  }, {
    key: "render",
    value: function render() {
      var _classNames, _classNames2;

      var _this$props = this.props,
          type = _this$props.type,
          title = _this$props.title,
          _this$props$size = _this$props.size,
          size = _this$props$size === void 0 ? '12' : _this$props$size,
          _this$props$color = _this$props.color,
          color = _this$props$color === void 0 ? '' : _this$props$color,
          _this$props$className = _this$props.className,
          className = _this$props$className === void 0 ? '' : _this$props$className,
          _this$props$tipProps = _this$props.tipProps,
          tipProps = _this$props$tipProps === void 0 ? {} : _this$props$tipProps,
          _this$props$style = _this$props.style,
          style = _this$props$style === void 0 ? {} : _this$props$style,
          rest = _objectWithoutProperties(_this$props, _excluded);

      var _this$state$iconfontp = this.state.iconfontplus,
          iconfontplus = _this$state$iconfontp === void 0 ? {} : _this$state$iconfontp;
      var CUSTOMIZE_ICON_NAME = this.config.CUSTOMIZE_ICON_NAME;
      return /*#__PURE__*/React.createElement(React.Fragment, null, title ? /*#__PURE__*/React.createElement(Tooltip, Object.assign({
        title: title
      }, tipProps), /*#__PURE__*/React.createElement("i", Object.assign({
        className: classNames((_classNames = {}, _defineProperty(_classNames, cpaasIconFont[CPAAS_ORIGIN_ICON_NAME], !iconfontplus["".concat(CUSTOMIZE_ICON_NAME, "-").concat(type)]), _defineProperty(_classNames, cpaasIconFont["".concat(CPAAS_ORIGIN_ICON_NAME, "-").concat(type)], cpaasIconFont["".concat(CPAAS_ORIGIN_ICON_NAME, "-").concat(type)]), _defineProperty(_classNames, iconfontplus[CUSTOMIZE_ICON_NAME], iconfontplus["".concat(CUSTOMIZE_ICON_NAME, "-").concat(type)]), _defineProperty(_classNames, iconfontplus["".concat(CUSTOMIZE_ICON_NAME, "-").concat(type)], iconfontplus["".concat(CUSTOMIZE_ICON_NAME, "-").concat(type)]), _defineProperty(_classNames, className, !!className), _classNames)),
        style: _objectSpread({
          fontSize: "".concat(size, "px"),
          color: color
        }, style)
      }, rest))) : /*#__PURE__*/React.createElement("i", Object.assign({
        className: classNames((_classNames2 = {}, _defineProperty(_classNames2, cpaasIconFont[CPAAS_ORIGIN_ICON_NAME], !iconfontplus["".concat(CUSTOMIZE_ICON_NAME, "-").concat(type)]), _defineProperty(_classNames2, cpaasIconFont["".concat(CPAAS_ORIGIN_ICON_NAME, "-").concat(type)], cpaasIconFont["".concat(CPAAS_ORIGIN_ICON_NAME, "-").concat(type)]), _defineProperty(_classNames2, iconfontplus[CUSTOMIZE_ICON_NAME], iconfontplus["".concat(CUSTOMIZE_ICON_NAME, "-").concat(type)]), _defineProperty(_classNames2, iconfontplus["".concat(CUSTOMIZE_ICON_NAME, "-").concat(type)], iconfontplus["".concat(CUSTOMIZE_ICON_NAME, "-").concat(type)]), _defineProperty(_classNames2, className, !!className), _classNames2)),
        style: _objectSpread({
          fontSize: "".concat(size, "px"),
          color: color
        }, style)
      }, rest)));
    }
  }]);

  return Icons;
}(React.Component);

export { Icons as default };